<template>
  <div>
    <!-- 历史搜索头部 -->
    <van-cell title="搜索历史">
      <div v-if="isDelete">
        <span @click='histories.splice(0)' style="margin-right: 10px">全部删除</span>
        <span @click='isDelete = false'>完成</span>
      </div>
      <van-icon v-else @click='isDelete = true' name="delete" />
      <!-- 历史搜索列表 -->
    </van-cell>
    <van-cell @click='onHistory(index, item)' v-for="(item, index) in histories" :key='item' :title="item">
      <van-icon v-show="isDelete" name="close" />
    </van-cell>
    <!-- 通用错误 -->
    <van-empty v-if="!histories.length" image="error" description="暂无搜索历史" />
  </div>
</template>

<script>
export default {
  name: 'histories',
  data () {
    return {
      isDelete: false
    }
  },
  props: {
    histories: {
      type: Array,
      required: true
    }
  },
  created () {

  },

  methods: {
    // 点击搜索历史进行删除
    onHistory (index, item) {
      if (this.isDelete) {
        this.histories.splice(index, 1)
      } else {
        this.$emit('search', item)
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
